package com.pwt.repository;

import com.pwt.entity.MASCHINE;
import com.pwt.model.ComboBoxModel;
import com.pwt.model.MachineManageModel;
import com.pwt.model.what.WhatChatsDataModel;
import com.pwt.repository.base.DataRepositoryExtension;
import org.springframework.data.jpa.repository.Query;

import java.util.*;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/18
 */
public class MASCHINERepositoryExtensionImpl extends DataRepositoryExtension<MASCHINE,Integer> implements MASCHINERepositoryExtension{


    @Override
    public List<MachineManageModel> queryMachineByMachineIds(Set<Integer> set) {
        String sql = " SELECT m.MAMASCHINE mId,m.MANR as mNumber,m.MABEZ mName,p.PRPRUEFER pId,p.PRNAME pNumber,p.PRVORNAME pName" +
                " from MASCHINE m\n" +
                " left JOIN ZU_MA_MAk z on m.MAMASCHINE =z.MAkEY\n" +
                " LEFT JOIN MASCHINkAT ma on ma.MAkNR=z.MAkNR\n" +
                " LEFT JOIN PRUEFER p on p.PRNAME = ma.MAkBEZ " +
                " where  m.MAMASCHINE in (?0)";
        return super.queryCustomBeanListBySql(MachineManageModel.class,sql,Arrays.asList(set.toArray()));
    }

    @Override
    public List<ComboBoxModel> queryMaschineByAll(String name) {
        String sql ="select MAMASCHINE as id,(mANR +' '+ mABEZ) as name from mASCHINE  ";
        if(name != null && !"".equals(name.trim())){
            sql+="where  mANR like N'%"+name+"%' or mABEZ like N'%"+name+"%'";
        }
        return this.queryCustomBeanListBySql(ComboBoxModel.class,sql);
    }


    public List<Map<String,Object>> getAllMaschine(){
        String sql ="SELECT p.PRPRUEFER,p.PRNAME,PRVORNAME,m.MAMASCHINE,m.MANR,m.MABEZ\n" +
                "from MASCHINE m\n" +
                "left JOIN ZU_MA_MAk z on m.MAMASCHINE =z.MAkEY\n" +
                "LEFT JOIN MASCHINkAT ma on ma.MAkNR=z.MAkNR\n" +
                "LEFT JOIN PRUEFER p on p.PRNAME = ma.MAkBEZ";
        return super.queryMapListBySql(sql);
    }


    public List<WhatChatsDataModel> queryWhatChatsList(){
        //MANR as
        String sql = "select MAMASCHINE as id,MABEZ as name from MASCHINE";
        return super.queryCustomBeanListBySql(WhatChatsDataModel.class,sql);
    }

}
